package cn.fl.project.controller;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.lsd.api.IHelpAppCrtUsrPrdService;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RequestMapping("/crtUsrPrd")
@Controller
public class CrtUsrPrdController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(CrtUsrPrdController.class);
    @Autowired
    private IHelpAppCrtUsrPrdService helpAppCrtUsrPrdService;

    @RequestMapping(value = "/selectCrtUsrCstPrdMsg.do", method = {RequestMethod.POST,RequestMethod.GET})
    @ResponseBody
    public Object selectCrtUsrCstPrdMsg(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "接口调用成功!");
        try {
            String crtUsrIdStr = request.getParameter("crtUsrId");
            BaseLogUtils.info(logger,"selectCrtUsrCstPrdMsg","begin 查询客户经理名下正常的产品进入方法crtUsrId="+ JSON.toJSONString(crtUsrIdStr));
            if(StringUtils.isEmpty(crtUsrIdStr)){
                BaseLogUtils.error(logger,"selectCrtUsrCstPrdMsg","查询客户经理名下正常的产品crtUsrId为空");
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("查询客户经理名下正常的产品crtUsrId为空");
                return request;
            }
            Long crtUsrId = Long.valueOf(crtUsrIdStr);
            List<Map> listMap = helpAppCrtUsrPrdService.selectCrtUsrCstPrdMsg(crtUsrId);
            Map<String, Object> map = new HashMap<>();
            map.put("list", listMap);
            result.setData(map);
        }catch (BaseException be){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(be.getError());
            BaseLogUtils.error(logger, "selectCrtUsrCstPrdMsg", "查询客户经理名下正常的产品失败，业务异常！", be);
        }catch (Exception e){
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("查询客户经理名下正常的产品失败,系统异常！");
            BaseLogUtils.error(logger, "selectCrtUsrCstPrdMsg", "查询客户经理名下正常的产品失败，业务异常！", e);
        }
        return result;

    }

}
